﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using dhDataAcess.orderLinqDAL;

namespace dhDataAcess.orderDAL
{
   public class custListDAL
    {
       string tableName = "custList";
        private SqlTransaction tran = null;
        private SqlConnection conn = null;
        public custListDAL(SqlTransaction _transaction, SqlConnection _conn)
        {
            tran = _transaction ;
            conn = _conn;
        }
        /// <summary>
        /// 插入客户信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int custListInsert(custListModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string insertstr = baseBLL.dTableColumnRead.insertSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                     new SqlParameter ("@mark",row .mark ),
                                    new SqlParameter ("@updateUser",row .updateUser),
                                    new SqlParameter ("@updateDate",row .updateDate),
                                    new SqlParameter ("@createUser",row .createUser),
                                    new SqlParameter ("@createDate",row .createDate),
                                    new SqlParameter ("@ctypeparent",row.ctypeparent ),
                                    new SqlParameter ("@ctypeMark",row .ctypeMark ),
                                    new SqlParameter ("@cType",row .cType ),
                                    new SqlParameter ("@taxMark",row .taxMark ),
                                    new SqlParameter ("@payType",row .payType  ),
                                    new SqlParameter ("@workerNum",row .workerNum  ),
                                    new SqlParameter ("@fax",row .fax ),
                                    new SqlParameter ("@mobilePhone",row .mobilePhone  ),
                                    new SqlParameter ("@qq",row .qq ),
                                    new SqlParameter ("@postCode",row .postCode  ),
                                    new SqlParameter ("@linkMan",row .linkMan  ),
                                    new SqlParameter ("@phone",row .phone ),
                                    new SqlParameter ("@custAdd",row .custAdd  ),
                                    new SqlParameter ("@custName",row .custName),
                                    new SqlParameter ("@custNum",row.custNum)
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = insertstr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 更新客户信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int custListUpdate(custListModel row)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string updatestr = baseBLL.dTableColumnRead.updateSqlStr(tableName).ToString();
            SqlParameter[] para = {
                                    new SqlParameter ("@mark",row .mark ),
                                    new SqlParameter ("@updateUser",row .updateUser),
                                    new SqlParameter ("@updateDate",row .updateDate),
                                    new SqlParameter ("@createUser",row .createUser),
                                    new SqlParameter ("@createDate",row .createDate),
                                    new SqlParameter ("@ctypeparent",row.ctypeparent ),
                                    new SqlParameter ("@ctypeMark",row .ctypeMark ),
                                    new SqlParameter ("@cType",row .cType ),
                                    new SqlParameter ("@taxMark",row .taxMark ),
                                    new SqlParameter ("@payType",row .payType  ),
                                    new SqlParameter ("@workerNum",row .workerNum  ),
                                    new SqlParameter ("@fax",row .fax ),
                                    new SqlParameter ("@mobilePhone",row .mobilePhone  ),
                                    new SqlParameter ("@qq",row .qq ),
                                    new SqlParameter ("@postCode",row .postCode  ),
                                    new SqlParameter ("@linkMan",row .linkMan  ),
                                    new SqlParameter ("@phone",row .phone ),
                                    new SqlParameter ("@custAdd",row .custAdd  ),
                                    new SqlParameter ("@custName",row .custName),
                                    new SqlParameter ("@custNum",row.custNum)
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = updatestr;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
        /// <summary>
        /// 删除一行客户信息表数据
        /// </summary>
        /// <param name="deptRow"></param>
        /// <returns></returns>
        public int custListDel(string custNum)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = CommandType.Text;
            string deletestr = baseBLL.dTableColumnRead.delSqlStr (tableName).ToString();
            SqlParameter[] para = {
                                  
                                    new SqlParameter ("@custNum",custNum)
                                };
            cmd.Parameters.AddRange(para);
            cmd.CommandText = deletestr ;
            cmd.Transaction = tran;
            int i = cmd.ExecuteNonQuery();
            return i;
        }
    }
}
